package com.example.ck.controller;

import com.example.ck.entity.Swiper;
import com.example.ck.service.SwiperService;
import com.example.ck.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * (Swiper)表控制层
 *
 * @author makejava
 * @since 2024-05-10 15:48:09
 */
@RestController
@CrossOrigin
@RequestMapping("/swiper")
public class SwiperController {
    /**
     * 服务对象
     */
    @Autowired
    private SwiperService swiperService;

    /**
     * 查询所有数据
     *
     * @return 单条数据
     */
    @GetMapping("")
    public ResultVo query() {
        List<Swiper> list = swiperService.query();
        return new ResultVo(list);
    }

    /**
     * 新增数据
     *
     * @param swiper 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    public ResultVo add(@RequestBody  Swiper swiper) {
        boolean b = swiperService.insert(swiper);
        if (b) {
            return new ResultVo(200, "新增成功", true, swiper);
        } else {
            return new ResultVo(201, "新增失败", false, null);
        }
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResultVo deleteById(Integer id) {
        boolean b = swiperService.deleteById(id);
        if (b) {
            return new ResultVo(200, "删除成功", true);
        } else {
            return new ResultVo(201, "删除失败", false);
        }
    }

}

